package io.qifan.desktop.server.domain.device;

import io.qifan.desktop.common.jpa.BaseEntity;
import io.qifan.desktop.server.domain.user.User;
import lombok.Data;
import org.apache.commons.lang3.RandomStringUtils;

import javax.persistence.*;

@Data
@Entity
@Table(name = "device")
public class Device extends BaseEntity {

    // 设备密码
    private String password;
    // 设备名称
    private String name;


    @ManyToOne
    @JoinColumn(name = "user_id")
    private User user;

    public void create(String deviceName, User user) {
        password = RandomStringUtils.randomAlphanumeric(6);
        this.user = user;
        this.name = deviceName;
    }
}
